#pragma once
#include <cerrno>
#include <stdlib.h>
#include <unistd.h>
#include <string>
#include <sys/socket.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include "LogMessage.hpp"

using std::string;

class Socket
{
    int _sockfd = -1;
    const static int s_backlog = 10;

public:
    Socket();

    //设置端口复用
    void SetPortReuse();

    void Bind(uint16_t port);

    void Listen();

    int Accept(string *ip, uint16_t *port);

    int Fd()
    {
        return _sockfd;
    }

    ~Socket()
    {
        if (_sockfd != -1)
        {
            close(_sockfd);
        }
    }
};